﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ReflexTérkép.Tests.dto;

namespace ReflexTérkép.Tests
{
    [TestClass]
    public class ComplexMapTests : TestBase
    {
        [TestMethod]
        public void Can_Map_Complex_Nested_Members()
        {
            // Arrange
            const int id = 1;
            const string firstName = "Bob";
            const string lastName = "Smith";
            const int orderId = 1;
            const decimal orderTotal = 50.50m;

            var dictionary = new Dictionary<string, object>
                                 {
                                     { "CustomerId", id },
                                     { "FirstName", firstName },
                                     { "LastName", lastName },
                                     { "Orders_OrderId", orderId },
                                     { "Orders_OrderTotal", orderTotal }
                                 }; 
            // Act
            var customer = ReflexMapper.Map<Customer>(dictionary);

            // Assert
            Assert.IsNotNull(customer);
            Assert.IsTrue(customer.CustomerId == id);
            Assert.IsTrue(customer.FirstName == firstName);
            Assert.IsTrue(customer.LastName == lastName);
            Assert.IsNotNull(customer.Orders);
            Assert.IsTrue(customer.Orders.Count == 1);
            Assert.IsTrue(customer.Orders.First().OrderId == orderId);
            Assert.IsTrue(customer.Orders.First().OrderTotal == orderTotal);
        }
    }
}
